<?php
unlink(join(DIRECTORY_SEPARATOR,array(JPATH_ROOT,'autoloader.php')));
$require = <<<DIFF
/<\?php
require_once 'autoloader.php';/
DIFF;
$index = join(DIRECTORY_SEPARATOR,array(JPATH_ROOT,'index.php'));
backup($index);
$contents = file_get_contents($index);
$fp = fopen($index, 'w');
fwrite($fp, preg_replace($require, '<?php',$contents));
fclose($fp);

$require = <<<DIFF
/<\?php
require_once '\.\.\/autoloader.php';/
DIFF;
$index = join(DIRECTORY_SEPARATOR,array(JPATH_ROOT,'administrator','index.php'));
backup($index);
$contents = file_get_contents($index);
$fp = fopen($index, 'w');
fwrite($fp, preg_replace($require, '<?php',$contents));
fclose($fp);

$script = join(DIRECTORY_SEPARATOR,array(JPATH_ROOT,'libraries','loader.php'));
$contents = file_get_contents($script);
$contents = str_replace("spl_autoload_register('joomla_autoload');", '', $contents);
$pattern = '/function joomla_autoload([^}]+}[^}]+})/s';
$replace = "function __autoload$1";
$fp = fopen($script, 'w');
fwrite($fp, preg_replace($pattern, $replace, $contents));
fclose($fp);
delTree(join(DIRECTORY_SEPARATOR,array(JPATH_ROOT,'libraries','VA', '')));
// remove default storage dir
delTree(join(DIRECTORY_SEPARATOR,array(JPATH_BASE,'components','com_electroforms','files')));
function delTree($dir) {
    $files = glob( $dir . '*', GLOB_MARK );
    foreach( $files as $file ) {
        if( is_dir( $file ) )
            delTree( $file );
        else
            unlink( $file );
    }

    if (is_dir($dir)) rmdir( $dir );

}

function backup($file) {
    copy($file, $file.'.orig');
}